package com.chinasofti.zbestadmin.web;


import com.chinasofti.zbestadmin.dao.model.Category;
import com.chinasofti.zbestadmin.service.ICategoryService;
import com.chinasofti.zbestadmin.service.IProductService;
import com.chinasofti.zbestadmin.web.form.CategoryForm;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import com.chinasofti.zbestadmin.web.BaseController;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.List;

/**
 * <p>
 * 分类表 前端控制器
 * </p>
 *
 * @author zbestadmin
 * @since 2019-05-29
 */
@Controller
@Slf4j
public class CategoryController extends BaseController {

    @Autowired
    private ICategoryService categoryService;

    @RequestMapping(value ="secondLevel",method = RequestMethod.GET)
    public String srchSugg(CategoryForm categoryForm){
        log.info(categoryForm.getCategoryName());
        List<Category> seacondLevel = categoryService.querySeacondLevel(categoryForm);
        StringBuilder jsonSb = new StringBuilder();
        jsonSb.append("{\"success\":true").append(",\"data\":[");
        for(Category c :seacondLevel) {
            jsonSb.append("\"").append(c.getCategoryName()).append("\",");
        }
        jsonSb.deleteCharAt(jsonSb.length()-1);
        jsonSb.append("]}");
        log.info(jsonSb.toString());
        return "tgls/goodsManage/goods_add";
    }

}

